package com.test.controller;

import com.test.entity.User;
import com.test.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by echisan on 2018/6/23
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserRepository userRepository;


    @GetMapping("/add")
    public String registerUser(@RequestParam("username") String username,
                               @RequestParam("password") String password){
        User user = new User(username, password);
        User save = userRepository.save(user);
        return save.toString();
    }

    @GetMapping("/get")
    @ResponseBody
    public List<User> getUser(){
        List<User> lists = (List<User>) userRepository.findAll();
        return lists;
    }
}
